<?php

namespace App\Http\Controllers\Admin\View;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Facades\Services\OrderService;
use ValiDate;
use App\Models\Order;

class OrderController extends Controller
{
    public function index(Request $request)
    {   

        $conditions = [];

        if(isset($request->status) && $request->status != ''){
            $conditions['status'] = $request->status;
        }
        if(isset($request->order_id) && $request->order_id != ''){
            $conditions['order_id'] = $request->order_id;
        }

    	return view('pages.admin.order.list',[
    		'orders' => OrderService::getOrders($conditions),
            'conditions' => $conditions,
            'status' => Order::$STATUS
    	]);
    }

    public function update(Request $request)
    {

        $rules = [
            'id' => 'required|exists:orders,id'
        ];

        ValiDate::valiDate($request,$rules);

        $data = $request->all();

    	return view('pages.admin.order.update',[
            'order' => OrderService::getOrder($data),
            'status' => Order::$STATUS
        ]);
    }

    public function details(Request $request)
    {
        $rules = [
            'id' => 'required|exists:orders,id'
        ];

        ValiDate::valiDate($request,$rules);

        $data = $request->all();

    	return view('pages.admin.order.details',[
            'order' => OrderService::getOrder($data)
        ]);
    }
}
